package org.jivesoftware.smackx.pubsub;

public class Subscription extends NodeExtension
{
  protected boolean configRequired;
  protected String id;
  protected String jid;
  protected State state;

  public Subscription(String paramString)
  {
    this(paramString, null, null, null);
  }

  public Subscription(String paramString1, String paramString2)
  {
    this(paramString1, paramString2, null, null);
  }

  public Subscription(String paramString1, String paramString2, String paramString3, State paramState)
  {
    super(PubSubElementType.SUBSCRIPTION, paramString2);
    this.configRequired = false;
    this.jid = paramString1;
    this.id = paramString3;
    this.state = paramState;
  }

  public Subscription(String paramString1, String paramString2, String paramString3, State paramState, boolean paramBoolean)
  {
    super(PubSubElementType.SUBSCRIPTION, paramString2);
    this.configRequired = false;
    this.jid = paramString1;
    this.id = paramString3;
    this.state = paramState;
    this.configRequired = paramBoolean;
  }

  private void appendAttribute(StringBuilder paramStringBuilder, String paramString1, String paramString2)
  {
    paramStringBuilder.append(" ");
    paramStringBuilder.append(paramString1);
    paramStringBuilder.append("='");
    paramStringBuilder.append(paramString2);
    paramStringBuilder.append("'");
  }

  public String getId()
  {
    return this.id;
  }

  public String getJid()
  {
    return this.jid;
  }

  public State getState()
  {
    return this.state;
  }

  public boolean isConfigRequired()
  {
    return this.configRequired;
  }

  public String toXML()
  {
    StringBuilder localStringBuilder = new StringBuilder("<subscription");
    appendAttribute(localStringBuilder, "jid", this.jid);
    if (getNode() != null)
      appendAttribute(localStringBuilder, "node", getNode());
    if (this.id != null)
      appendAttribute(localStringBuilder, "subid", this.id);
    if (this.state != null)
      appendAttribute(localStringBuilder, "subscription", this.state.toString());
    localStringBuilder.append("/>");
    return localStringBuilder.toString();
  }

  public static enum State
  {
    static
    {
      pending = new State("pending", 2);
      none = new State("none", 3);
      State[] arrayOfState = new State[4];
      arrayOfState[0] = subscribed;
      arrayOfState[1] = unconfigured;
      arrayOfState[2] = pending;
      arrayOfState[3] = none;
      ENUM$VALUES = arrayOfState;
    }
  }
}